class_name Knife
extends Collectible



func _ready():
	sprite.position = Vector2.UP * height
	damageEmitter.position = Vector2.UP * height
	damageEmitter.area_entered.connect(on_emit_damage)
	damageEmitter.body_exited.connect(on_leave_screen)

	super._ready()



func on_emit_damage(receiver_area: Area2D):
	var damage_receiver: DamageReceiver = receiver_area as DamageReceiver
	if damage_receiver == null:
		return

	EntityManager.spawn_spark.emit(global_position)

	damage_receiver.damage_received.emit(damage,
										receiver_area.global_position - damageEmitter.global_position,
										DamageReceiver.HitType.KNOCK_DOWN)
	SoundPlayer.play(SoundManager.Sound.KNIFE_HIT, true)
	queue_free()


func on_leave_screen(_body: Node2D):
	call_deferred("queue_free")
